﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;

using DataAccess;
using Entities;
using Common;

namespace BusinessLogic
{
    public static class ThongTinMaVach
    {
        //Entities
        public static Entities.ThongTinMaVach[] sp_LayBang_ThongTinMaVachHangHoa(Entities.ThongTinMaVach mavach)
        {
            Entities.ThongTinMaVach[] arrC = null;
            try
            {
                string sql = "exec sp_LayBang_ThongTinMaVachHangHoa";
                SqlConnection cn = DataAccess.Connection.OpenConnection();
                SqlCommand cmd = new SqlCommand(sql, cn);
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                ArrayList arr = new ArrayList();
                while (dr.Read())
                {
                    mavach = new Entities.ThongTinMaVach();
                    mavach.ChonIn = false;
                    mavach.MaHangHoa = dr[0].ToString();
                    mavach.TenHangHoa = dr[1].ToString();
                    mavach.GiaNhap = dr[2].ToString();
                    mavach.GiaBanBuon = dr[3].ToString();
                    mavach.GiaBanLe = dr[4].ToString();
                    mavach.GhiChu = "";
                    arr.Add(mavach);
                }
                int n = arr.Count;
                if (n == 0) { arrC = null; }
                arrC = new Entities.ThongTinMaVach[n];
                for (int i = 0; i < n; i++)
                {
                    arrC[i] = (Entities.ThongTinMaVach)arr[i];
                }
                cmd.Connection.Dispose();
                cn.Close();
                DataAccess.Connection.CloseConnection();
            }

            catch (Exception ex)
            { string s = ex.Message.ToString(); arrC = null; }
            return arrC;
        }
    }
}
